<script>
    //解构对象，将对象中name的值取出赋值给n，将price的值取出赋值给p
    let {name:n,price:p}={name:"手机",price:"1998",weight:"180"};
    console.log(n,p);

    function getData(){
        return {name:"手机",price:"1998",weight:"180"};
    }
    //等价于let {name:name,price:price}=getData();
    let {name,price}=getData();

    //允许多次复用
    let obj={},data={name:"手机",price:"1998",weight:"180"};
    ({name:obj.x,price:obj.y,name:obj["z"]}=data);  //如果不是赋值表达式，则需要括号
    console.log(obj);

    //解构允许与rest一起复合使用,注意是左边是属性，右边是变量
    let {name:pname,...phone}=data;
    console.log(pname,phone);
</script>